package ch.ethz.fcl.metrobuzz.render.accessbility.interaction;

import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;
import ch.ethz.fcl.metrobuzz.render.accessbility.AccessibilityRender;

public class AcceGlobalPanel extends JPanel {
	private static final long serialVersionUID = -7121811087445725047L;

	private JCheckBox acceMapCB;
	private JCheckBox roadEffiCB;

	public AcceGlobalPanel() {
		setBackground(Color.lightGray);
		setBorder(BorderFactory
				.createTitledBorder("Global Accessibility Views"));
		setLayout(new MigLayout());

		acceMapCB = new JCheckBox("       Accessibility Level Map",
				AccessibilityRender.ACCESSIBILITY_MAP_VIEW);
		acceMapCB.setBackground(Color.LIGHT_GRAY);
		acceMapCB.addItemListener(new CheckBoxChangeListener());

		roadEffiCB = new JCheckBox("       Road Efficiency Map",
				AccessibilityRender.ROAD_EFFICIENCY_VIEW);
		roadEffiCB.setBackground(Color.LIGHT_GRAY);
		roadEffiCB.addItemListener(new CheckBoxChangeListener());

		this.add(acceMapCB, "wrap");
		this.add(roadEffiCB, "wrap");
	}

	public JCheckBox getAcceMapCB() {
		return acceMapCB;
	}

	public JCheckBox getRoadEffiCB() {
		return roadEffiCB;
	}

	class CheckBoxChangeListener implements ItemListener {
		@Override
		public void itemStateChanged(ItemEvent event) {
			Object source = event.getSource();
			if (source instanceof JCheckBox) {
				JCheckBox cb = (JCheckBox) source;
				if (cb.isSelected()) {
					if (cb.getText().contains("Accessibility Level"))
						AccessibilityRender.ACCESSIBILITY_MAP_VIEW = true;
					else if (cb.getText().contains("Road Efficiency"))
						AccessibilityRender.ROAD_EFFICIENCY_VIEW = true;
				} else {
					if (cb.getText().contains("Accessibility Level"))
						AccessibilityRender.ACCESSIBILITY_MAP_VIEW = false;
					else if (cb.getText().contains("Road Efficiency"))
						AccessibilityRender.ROAD_EFFICIENCY_VIEW = false;
				}
			}
		}
	}
}
